import React, { useReducer } from 'react'
// useReducer ==>  createStore
let reducer = (state, action) => {
    switch(action.type) {
        case "CHANGE_NAME":
            state.name = "赵六"
            return { ...state }
    }
}

let initState = {
    name: "王五",
    age: 25
}
function Reducer() {
    const [state, dispatch] = useReducer(reducer, initState)
    return (
        <div>
            <p>
                姓名: { state.name }
            </p>
            <p>
                年龄: { state.age }
            </p>
            <button onClick = {() => {
                dispatch({ type: "CHANGE_NAME" })
            }}>改变姓名</button>
        </div>
    )
}

export default Reducer
